package com.ktdaddy.controller.system;

import com.ktdaddy.request.CreatePermissionReq;
import com.ktdaddy.request.CreateRoleReq;
import com.ktdaddy.request.UpdatePermissionReq;
import com.ktdaddy.vo.PermVO;
import com.ktdaddy.service.PermService;
import com.ktdaddy.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: lujianhao
 * @Description: 权限控制器
 * @Date: 2021/7/21 10:53 上午
 */
@Api(value = "权限相关", tags = {"权限相关"})
@RequestMapping("/whale/system/permission")
@RestController
public class PermissionController {

    @Autowired
    private PermService permService;

    @ApiOperation(value = "获取菜单查询列表",notes = "获取菜单列表",httpMethod = "GET")
    @GetMapping("getPermList")
    public ApiResponse getMenuList(@RequestParam(value = "menuName",required = false) String menuName,
                                   @RequestParam(value = "status",required = false)Integer status){
        List<PermVO> menuList = permService.getPermList(menuName,status);
        return ApiResponse.ok(menuList);
    }

    @ApiOperation(value = "创建权限",notes = "创建权限",httpMethod = "POST")
    @PostMapping("/createPermission")
    public ApiResponse createPermission(@RequestBody @Valid CreatePermissionReq createPermissionReq){
        boolean result = permService.createPermission(createPermissionReq);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "更新权限",notes = "更新权限",httpMethod = "POST")
    @PostMapping("/updatePermission")
    public ApiResponse updatePermission(@RequestBody @Valid UpdatePermissionReq updatePermissionReq){
        boolean result = permService.updatePermission(updatePermissionReq);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "校验权限名称是否存在",notes = "校验权限名称是否存在",httpMethod = "GET")
    @GetMapping("isPermissionExist")
    public ApiResponse isPermissionExist(@RequestParam(value = "permissionName") String permissionName){
        boolean result = permService.isPermissionExit(permissionName);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "删除权限",notes = "删除权限",httpMethod = "GET")
    @GetMapping("/deletePermission")
    public ApiResponse deletePermission(@RequestParam(value = "permissionId") Integer permissionId){
        permService.deletePermission(permissionId);
        return ApiResponse.ok();
    }


}
